﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Utils;
using Spore.Validator;


namespace Client
{
    public partial class BaseForm : XtraForm
    {

        protected ErrorProvider ep;
        protected  Spore.Validator.FormValidator FormValidator;
        public BaseForm()
        {
            InitializeComponent();
            ep = new ErrorProvider();
            ep.BlinkStyle = ErrorBlinkStyle.NeverBlink;
            FormValidator = new FormValidator(ep);
        }

        /// <summary>
        /// 为控件添加必填项标记
        /// </summary>
        /// <param name="x">标记的x坐标(相对控件的坐标)</param>
        /// <param name="y">标记的y坐标(相对控件的坐标)</param>
        /// <param name="controls">需要添加控件的标记</param>
        protected void NecessaryRemark(int x, int y, params Control[] controls)
        {
            foreach (Control control in controls)
            {
                DevExpress.XtraEditors.LabelControl labelControl = new DevExpress.XtraEditors.LabelControl();
                labelControl.Location = new Point(control.Location.X + control.Width + x, control.Location.Y + y);
                labelControl.Text = "*";
                labelControl.ForeColor = Color.Red;
                control.Parent.Controls.Add(labelControl);
                control.VisibleChanged += (object sender, EventArgs e) => { labelControl.Visible = control.Visible; };
            }
        }

        /// <summary>
        /// 为控件添加必填项标记
        /// </summary>
        /// <param name="controls">需要添加控件的标记</param>
        protected void NecessaryRemark(params Control[] controls)
        {
            NecessaryRemark(1, 5, controls);
        }

        protected override void WndProc(ref Message msg)
        {
            if (msg.Msg == GlobalInfo.msg_winMessage)
            {
               this.OnServiceInfo(msg);
               return;
            }
            base.WndProc(ref msg);
        }

        protected virtual void OnServiceInfo(Message msg)
        {

        }

    }
}
